import request from "@/utils/request"

// 获取用户列表
export const getUserList = async (params?: { pageNum?: number, pageSize?: number }) => {
    return await request({
            url: '/system/user/list',
            method: 'GET',
            params: {
                pageNum: params?.pageNum || 1,
            pageSize: params?.pageSize || 10
}
})
}

// 岗位列表
export const getPositionList = async (params?: { pageNum?: number, pageSize?: number, keyword?: string }) => {
    return await request({
            url: '/position/list',
            method: 'GET',
            params: {
                pageNum: params?.pageNum || 1,
            pageSize: params?.pageSize || 10,
        keyword: params?.keyword || ""
}
})
}
// 岗位创建
export const positionAdd = (data: object) => {
    return request({ url: '/position/add', method: "POST",data, headers: { loading: true } })
}
// 岗位更新
export const positionUpdate = (data: object) => {
    return request({ url: '/position/update', method: "POST",data , headers: { loading: true } })
}
// 岗位更新状态
export const positionUpdateStatus = (data: object) => {
    return request({ url: '/position/updateStatus', method: "POST",data, headers: { loading: true }  })
}
// 岗位删除
export const positionDel = (positionId: number) => {
    return request({ url: '/position/delete', method: "DELETE", params: { positionId } })
}

// 岗位详情
export const getPositionDetail = (positionId: any) => {
    return request({ url: '/position/getPosition', method: "GET", params: { positionId } });
};

// 用户信息创建
export const userPost = (data: object) => {
    return request({ url: '/system/user', method: "POST",data, headers: { loading: true } })
}
// 用户信息修改
export const userPut = (data: object) => {
    return request({ url: '/system/user', method: "PUT",data, headers: { loading: true } })
}
// 用户信息详情
export const userGet = (userId: string) => {
    return request({ url: `/system/user/${userId}`, method: "GET", params: { userId } });
};


// 客户创建
export const customersAdd = (data: object) => {
    return request({ url: '/customers/add', method: "POST",data, headers: { loading: true } })
}
// 客户详情
export const getCusomer = (id: string) => {
    return request({ url: '/customers/getCusomer', method: "POST", data: { customerId: id } });
};
// 客户列表 管理员
export const cusomerList = async (params?: { pageNum?: number, pageSize?: number }) => {
    return await request({
            url: '/customers/list',
            method: 'GET',
            params: {
                pageNum: params?.pageNum || 1,
            pageSize: params?.pageSize || 10
}
})
}
// 客户列表 业务员
export const cusomerListMy = async (params?: { pageNum?: number, pageSize?: number }) => {
    return await request({
            url: '/customers/listMy',
            method: 'GET',
            params: {
                pageNum: params?.pageNum || 1,
            pageSize: params?.pageSize || 10
}
})
}
// 客户修改、更新
export const cusomerUpdate = (messageId: string) => {
    return request({ url: '/customers/update', method: "POST",data :{customerId: messageId}, headers: { loading: true } });
};
// 今日新增
export const todayNewAdditions = () => {
    return request({ url: '/customers/todayNewAdditions', method: "GET",  });
};
// 客户转化（管理员）
export const customerConversion = () => {
    return request({ url: '/customers/customerConversion', method: "GET",  });
};
// 分享统计（管理员）
export const shareStatistic = () => {
    return request({ url: '/customers/shareStatistic', method: "GET",  });
};
// 业务员排行
export const salesmanRanking = () => {
    return request({ url: '/customers/salesmanRanking', method: "GET",  });
};
// 业务员
export const salesmanStatistic = () => {
    return request({ url: '/customers/salesmanStatistic', method: "GET",  });
};

// 文件上传
export const uploadFile = (file: File, type: string = 'job') => {
    const formData = new FormData()
    formData.append('files', file)
    formData.append('type', type)
    return request({
        url: '/common/uploads',
        method: 'POST',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data',
            loading: true
        }
    })
}

// 批量删除岗位
export const batchDeletePositions = (positionIds: number[]) => {
    return request({
        url: '/position/batchDelete',
        method: 'DELETE',
        data: { positionIds },
        headers: { loading: true }
    })
}


// 网站列表
export const getWwwinfoList = async (params?: { pageNum?: number, pageSize?: number, keyword?: string }) => {
    return await request({
            url: '/wwwinfo/list',
            method: 'GET',
            params: {
                pageNum: params?.pageNum || 1,
            pageSize: params?.pageSize || 10,
        keyword: params?.keyword || ""
}
})
}
// 网站创建
export const wwwinfoAdd = (data: object) => {
    return request({ url: '/wwwinfo/add', method: "POST",data, headers: { loading: true } })
}
// 网站更新
export const wwwinfoUpdate = (data: object) => {
    return request({ url: '/wwwinfo/update', method: "POST",data , headers: { loading: true } })
}
// 网站更新状态
export const wwwinfoUpdateStatus = (data: object) => {
    return request({ url: '/wwwinfo/updateStatus', method: "POST",data, headers: { loading: true }  })
}
// 网站删除
export const wwwinfoDel = (id: number) => {
    return request({ url: '/wwwinfo/delete', method: "DELETE", params: { id } })
}

// 网站详情
export const getWwwinfoDetail = (id: any) => {
    return request({ url: '/wwwinfo/getWwwInfo', method: "GET", params: { id } });
};
// 批量删除网站
export const batchDeleteWwwinfo = (ids: number[]) => {
    return request({
        url: '/wwwinfo/batchDelete',
        method: 'DELETE',
        data: { ids },
        headers: { loading: true }
    })
}